package com.situ.mall;

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.data.redis.core.RedisTemplate;

import java.util.Set;

@SpringBootTest
public class RedisTestSet {
    @Autowired
    private RedisTemplate redisTemplate;

    @Test
    public void testSetValue() {
        redisTemplate.opsForSet().add("nameSet", "张飞");
        redisTemplate.opsForSet().add("nameSet", "关羽");
        redisTemplate.opsForSet().add("nameSet", "赵云");
        redisTemplate.opsForSet().add("nameSet", "赵云");
    }

    @Test
    public void testGetValue() {
        Set members = redisTemplate.opsForSet().members("nameSet");
        System.out.println(members);
    }

    //删除集合中某个元素
    @Test
    public void testDeleteValue() {
        redisTemplate.opsForSet().remove("nameSet", "关羽");
    }

    //移除整个集合
    @Test
    public void testDeleteAllValue() {
        redisTemplate.delete("nameSet");
    }
}
